package frontend.login.controller;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import core.profile.dao.RegisterDao;
import core.profile.model.BasicCredential;
import core.profile.model.SecurityQuestion;
import frontend.user.controller.GetDataByEmailId;
import frontend.user.dao.EditProfileDao;

public class UpdateSecurityQuestions extends ActionSupport{

	private static final long serialVersionUID = -7722007150983614611L;
	private String qus1;
	private String qus2;
	private String ans1;
	private String ans2;
	private BasicCredential basicCredential;
	private SecurityQuestion securityQuestion;
	
	

	public String getQus1() {
		return qus1;
	}

	public void setQus1(String qus1) {
		this.qus1 = qus1;
	}

	public String getQus2() {
		return qus2;
	}

	public void setQus2(String qus2) {
		this.qus2 = qus2;
	}

	public String getAns1() {
		return ans1;
	}

	public void setAns1(String ans1) {
		this.ans1 = ans1;
	}

	public String getAns2() {
		return ans2;
	}

	public void setAns2(String ans2) {
		this.ans2 = ans2;
	}

	public BasicCredential getBasicCredential() {
		return basicCredential;
	}

	public void setBasicCredential(BasicCredential basicCredential) {
		this.basicCredential = basicCredential;
	}

	public SecurityQuestion getSecurityQuestion() {
		return securityQuestion;
	}

	public void setSecurityQuestion(SecurityQuestion securityQuestion) {
		this.securityQuestion = securityQuestion;
	}

	public String execute() throws Exception{
		
		Map<String, Object> session = ActionContext.getContext().getSession();
		if(session.get("emailId")!=null){
			basicCredential=GetDataByEmailId.getBasicCredentialByUserId(session.get("emailId").toString());
			securityQuestion=basicCredential.getSecurityquestion();
			if(null==securityQuestion){
				securityQuestion=new SecurityQuestion();
			}
			securityQuestion.setSeq1(this.getQus1());
			securityQuestion.setAns1(this.getAns1());
			securityQuestion.setSeq2(this.getQus2());
			securityQuestion.setAns2(this.getAns2());
			basicCredential.setSecurityquestion(securityQuestion);
			EditProfileDao.updateBasicCredential(basicCredential);
			EditProfileDao.updateSecurityQuestion(securityQuestion);			
			
			return SUCCESS;
		}else{
			return ERROR;
		}
		
		
		
		
				
	}
}
